package cn.zebra.dev.member.module.security.entity;

import cn.zebra.dev.base.module.member.entity.BaseMember;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @author runnable@sina.cn
 */
public class MemberDetailsEntity implements UserDetails {
    /**
     * 登录用户名(可能是手机 或者 用户名)
     */
    private String loginName;
    /**
     * 用户信息
     */
    private BaseMember member;

    private Boolean accountNonExpired;

    private Boolean enabled;

    private Boolean credentialsNonExpired;

    private Boolean accountNonLocked;

    public void setMember(BaseMember member) {
        this.member = member;
    }

    public MemberDetailsEntity(BaseMember member) {
        this.member = member;
        this.enabled = member.getStatus() != -1;
        this.accountNonLocked = true;
        this.accountNonExpired = true;
        this.credentialsNonExpired = true;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return this.member.getPassword();
    }

    @Override
    public String getUsername() {
        return this.loginName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return accountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return credentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }

    public BaseMember getMember() {
        return member;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }
}